/*
	Copyright (C) 2010 2011 Rémi Thebault

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PROCYCLE_H
#define PROCYCLE_H

#include <QtGui/QMainWindow>
#include <QItemSelection>
#include <QComboBox>
#include <QSpinBox>
#include <QGraphicsScene>

#include <procycle/cycle.h>

#include "globals.h"

#include "ui_procycle.h"


class TaskSelectionModel;
class TaskTreeView;
class TaskTreeModel;
class GanttView;
class GanttScene;
class TimeAxis;
class ViewManager;


class ProCycle : public QMainWindow
{
	Q_OBJECT

public:
	ProCycle(int argc, char** argv);
	~ProCycle();


	PC::Cycle* activeCycle() {
		return m_cycle;
	}


	void updateActions();


	int headerHeight() const {
		return 20;
	}

	int rowHeight() const {
		return 25;
	}


	QString taskTreeHeaderColName(PC::Task::Data td) const;

	TaskTreeModel* taskTreeModel() const {
		return m_taskTreeModel;
	}

	GanttView* ganttView() const {
		return m_ganttView;
	}

	GanttScene* ganttScene() const {
		return m_ganttScene;
    }

    ViewManager* viewManager() const {
        return m_viewManager;
    }

    TimeAxis* axis() const {
        return m_axis;
    }


	TaskSelectionModel* selectionModel() const {
		return m_selectionModel;
    }

    const Ui::ProCycleClass * get_ui () const {
        return &ui;
    }

public slots:

	void about();
	void preferences();
	void quit();

    void undo() {}
    void redo() {}

    void cut() {}
    void copy() {}
    void paste();
    void clipboardChanged();

	void newProject() {}
	void openProject() {}
	void saveProject() {}
	void saveProjectAs() {}
	void projectProperties() {}
	void closeProject() {}

	void newCycle() {}
	void deleteCycle() {}
	void cycleProperties() {}
	void importCycle();
	void exportCycle();
    void print();

	void newTask();
	void deleteTask();
	void indentTask();
	void unindentTask();
	void taskProperties();

	void deleteLink();
	void changeLinkLag(int newVal);
	void changeLinkType(int newIndex);

	void toggleFullScreen(bool on);


	void toggleTaskMode(bool on);
	void toggleLinkMode(bool on);
    void toggleZoomWindow(bool on);

	void processSelectedTaskChanged(PC::Task* selected, PC::Task* unselected);
	void processSelectedLinkChanged(PC::Link* selected, PC::Link* unselected);


protected:

    void keyReleaseEvent(QKeyEvent *event);


private:

    void createUI();
    void initSizePolicy();

	Ui::ProCycleClass	ui;
    bool                m_editModeLock;

	TaskTreeView*		m_taskTreeView;
	TaskTreeModel*		m_taskTreeModel;

	GanttView*			m_ganttView;
    GanttScene*			m_ganttScene;
    QGraphicsScene*     m_rulerScene;
    TimeAxis*           m_axis;

    ViewManager*        m_viewManager;

	QToolBar*			m_linkToolBar;
	QAction*			m_actionDeleteLink;
	QSpinBox*			m_spinLinkLag;
	QComboBox*			m_comboLinkType;

	TaskSelectionModel*	m_selectionModel;

    PC::Cycle*			m_cycle;

};

#endif // PROCYCLE_H
